package com.whfp.coky.ui.task.act.fluor

import com.whfp.coky.api.error.ErrorResult
import com.whfp.coky.databinding.ActivityFluorThresholdDetailBinding
import com.whfp.coky.manager.InputTextManage
import com.whfp.coky.other.Constants
import com.whfp.coky.ui.base.BaseActivity
import com.whfp.coky.ui.task.vm.fluor.ThresholdDetailVM
import com.whfp.coky.widget.clicks


class ThresholdDetailAct : BaseActivity<ThresholdDetailVM, ActivityFluorThresholdDetailBinding>() {

    override fun initView() {
        vModel.initIdBundle(getBundle()?.getInt(Constants.ID))
        buildEtListener()
        vBinding.btnSave.clicks {
                vModel.checkInput()
        }
    }

    override fun initData() {}


    //    监听新增数据(至少输入一条阈值)
    private fun buildEtListener() {
        vBinding.btnSave.let {
            InputTextManage.with(this).apply {
                addView(vBinding.et01)
                addView(vBinding.et02)
                addView(vBinding.et03)
                setMain(it)
                build()
            }
        }
    }

    override fun errorResult(errorResult: ErrorResult) {
        super.errorResult(errorResult)
        if (errorResult.code == vModel.COMMIT_OK){
            postDelayed(Runnable { finish() },200)
        }
    }
}